from django_filters import rest_framework as filters
from mongolog.models import FileLog
from zmad.models import ZTPDevice
from .models import DeviceInfo


class TerminalFilter(filters.FilterSet):
    username = filters.CharFilter(field_name='user__username')

    class Meta:
        model = DeviceInfo
        fields = ('username', 'is_secure')


class FileFilter(filters.FilterSet):
    is_secret = filters.BooleanFilter(field_name='sen_level', method='filter_sen_level')

    def filter_sen_level(self, queryset, name, value):
        lookup = '__gt' if value else ''
        return queryset.filter(**{name + lookup: 0})

    class Meta:
        model = FileLog
        fields = ('is_secret', 'source', "sen_level", "sen_type")


class PCTerminalFilter(filters.FilterSet):
    is_secure = filters.CharFilter(field_name='is_secure')

    class Meta:
        model = ZTPDevice
        fields = ('is_secure', )
